#! /bin/bash

P=5001

start()
{
    tmp=`ps -ef | grep "./allLook/allLook" | wc -l`
    if [ $tmp -gt 1 ]; then 
      echo "The server arealdy started...abort!" 
      exit 1 
    fi 

    rm logs/allLook.log
    rm errs/allLook.log
    sleep 2

    echo "start allLook"
    nohup ./allLook/allLook -P ${P} 1>logs/allLook.log 2>errs/allLook.log &
    echo "ok!"
    sleep 1

    ps -ef | grep allLook
}


stop() {
    gre_str="./allLook/allLook"
    echo ${gre_str}
    k_pid=$(ps -ef | grep "${gre_str}" |grep -v grep|awk '{printf $2 "\n"}')
    for i in $k_pid
    do
    echo $i 
    $(kill -9 $i)
    done
}

usage()
{
        echo "Usage: $0 [start|stop|restart]"
}

if [ $# -lt 1 ];then
        usage
        exit
fi

if [ "$1" = "start" ];then
        start

elif [ "$1" = "stop" ];then
        stop

elif [ "$1" = "restart" ];then
        stop
        start

else
        usage
fi